<?php

namespace App\Admin\Actions\Grid\Tools\SwtDheMachine;

use App\Admin\Actions\Grid\Tools\BaseTools;
use App\Admin\Logic\Dhe\DheMachineLogic;
use Dcat\Admin\Actions\Response;
use Dcat\Admin\Traits\HasPermissions;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class MachineSyncData extends BaseTools
{
	protected $title = '云端同步';

    protected $style = 'btn btn-danger';

    protected $icon = 'icon-cloud';

    /**
     * Handle the action request.
     *
     * @param Request $request
     *
     * @return Response
     */
    public function handle()
    {
        $res = DheMachineLogic::refreshMachineList();

        return $this->response()
            ->success($res)
            ->refresh();
    }

    /**
	 * @return string|array|void
	 */
	public function confirm()
	{
        return ['确定同步大黄鹅设备码？', '确认后将会拉取所有设备信息，这需要一定的时间'];
	}

    /**
     * @param Model|Authenticatable|HasPermissions|null $user
     *
     * @return bool
     */
    protected function authorize($user): bool
    {
        return true;
    }

    /**
     * @return array
     */
    protected function parameters()
    {
        return [];
    }
}
